﻿Imports System.ComponentModel
Imports BusinessLayer
Imports Ocean.OceanFramework.MVVM
Imports BusinessEntityObjects
Imports Ocean.OceanFramework.CommonDialog
Imports Ocean.OceanFramework.WPF.Utility.Helpers

Public Class ContactViewModel
    Inherits EditFormViewModelBase

#Region " Declarations "

    Private _cmdBlogNavigateCommand As ICommand
    Private _cmdFeedNavigateCommand As ICommand
    Private _objContact As Contact

#End Region

#Region " Properties "

    Public Property Contact() As Contact
        Get
            Return _objContact
        End Get
        Set(ByVal Value As Contact)
            _objContact = Value
            OnPropertyChanged("Contact")
        End Set
    End Property

#End Region

#Region " Command Properties "

    Public ReadOnly Property BlogNavigateCommand() As ICommand
        Get

            If _cmdBlogNavigateCommand Is Nothing Then
                _cmdBlogNavigateCommand = New RelayCommand(AddressOf BlogNavigateExecute, AddressOf CanBlogNavigateExecute)
            End If

            Return _cmdBlogNavigateCommand
        End Get
    End Property

    Public ReadOnly Property FeedNavigateCommand() As ICommand
        Get

            If _cmdFeedNavigateCommand Is Nothing Then
                _cmdFeedNavigateCommand = New RelayCommand(AddressOf FeedNavigateExecute, AddressOf CanFeedNavigateExecute)
            End If

            Return _cmdFeedNavigateCommand
        End Get
    End Property

#End Region

#Region " Constructor "

    Public Sub New(ByVal obj As Contact)
        MyBase.ViewModelFriendlyName = "Contacts"
        _objContact = obj
    End Sub

#End Region

#Region " Command Methods "

    Private Sub BlogNavigateExecute(ByVal param As Object)

        If CanBlogNavigateExecute(param) Then

            Try
                StartProcessWithFileName(Me.Contact.BlogURL)

            Catch ex As Exception
                ViewModelUIService.ExceptionDialog(ex)
            End Try

        End If

    End Sub

    Private Function CanBlogNavigateExecute(ByVal param As Object) As Boolean
        Return _objContact IsNot Nothing AndAlso _objContact.BlogURL.Length > 0 AndAlso String.IsNullOrEmpty(_objContact.Item("BlogURL"))
    End Function

    Private Function CanFeedNavigateExecute(ByVal param As Object) As Boolean
        Return _objContact IsNot Nothing AndAlso _objContact.FeedURL.Length > 0 AndAlso String.IsNullOrEmpty(_objContact.Item("FeedURL"))
    End Function

    Private Sub FeedNavigateExecute(ByVal param As Object)

        If CanFeedNavigateExecute(param) Then

            Try
                StartProcessWithFileName(Me.Contact.FeedURL)

            Catch ex As Exception
                ViewModelUIService.ExceptionDialog(ex)
            End Try

        End If

    End Sub

#End Region

End Class
